var mapIds = new Array();
var 准备地图 = 992000000;
var badMaps = [19, 29, 37, 38, 42, 43, 46];
var BGM = [
    ["阿里安特", "Bgm14/Ariant"],
    ["明珠港", "Bgm02/AboveTheTreetops"],
    ["射手村", "Bgm00/FloralLife"],
    ["勇士部落", "Bgm00/Nightmare"],
    ["废弃都市", "Bgm01/BadGuys"],
    ["魔法密林", "Bgm02/WhenTheMorningComes"],
    ["林中之城", "Bgm00/SleepyWood"],
    ["埃欧雷", "Bgm25/WindAndFlower"],
    ["天空之城", "Bgm04/Shinin'Harbor"],
    ["冰封雪域", "Bgm03/SnowyVillage"],
    ["水下世界", "Bgm11/Aquarium"],
    ["玩具城", "Bgm06/FantasticThinking"],
    ["神木村", "Bgm13/Leafre"],
    ["圣地", "Bgm18/QueensGarden"],
    ["埃德尔斯坦", "Bgm22/EdelsteinCity"],
    ["玛加提亚", "Bgm12/Dispute"],
    ["武陵", "Bgm15/MureungHill"],
    ["里恩", "Bgm19/RienVillage"],
    ["尖耳狐狸村", "Bgm36/foxvillage"],
    ["万神殿", "Bgm27/Pantheon"],
    ["童话村", "Bgm11/DownTown"]
];
var mobs27F = [2600106, 9800145];
var mobsName27F = ["沙漠蛇先生", "壁虎"];
var mobs37F = [9309016, 9309017, 9309018, 9309019];
var mobsName37F = ["丁满", "秃鹫先生", "沙漠土拨鼠", "沙漠毒蝎"];
var mobs42F = [9309023, 9309024, 9309025, 9309026];
var mobsName42F = ["橡木甲虫", "金属甲虫", "哈维", "血腥哈维"];

function init() {
    em.setProperty("state", 0);
    em.setProperty("time", 0);
    em.setProperty("leader", "true");
    for (var a = 1; a <= 50; a++) {
        mapIds.push(992000000 + a * 1000);
        if (a == 14) {
            mapIds.push(992000000 + a * 1000 + 1);
            mapIds.push(992000000 + a * 1000 + 2)
        }
    }
}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance("副本_起源之塔");
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully();
        d.killAllMonsters(false)
    }
    return c
}

function onPlayerRegistered(b, a) {
    a.setReviveCount(-100);
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0));
    b.startEventTimer(em.getProperty("time"))
}

function onPlayerRevived(b, a) {
    return false
}

function onMapChanged(d, c, b) {
    if (mapIds.indexOf(b) < 0) {
        on玩家退场(d, c, false);
        return
    }
    var e = (b - 准备地图) / 1000;
    em.setProperty("state", e);
    if (e > 1) {
        d.restartEventTimer(d.getTimeLeft())
    }
    switch (e) {
        case 1:
            initProp("stage" + e + "_kill", 0);
            initProp("stage" + e + "_damage", 0);
            c.getAPI().setNumberForQuestInfo(992001000, "damage", 0);
            break;
        case 3:
            initProp("stage" + e + "_bet_egg_on_left", 0);
            initProp("stage" + e + "_bet_egg_on_right", 0);
            initProp("stage" + e + "_winner", 0);
            d.schedule("stage" + e + "_Fight", randomNum(1 * 60 * 1000, 3 * 60 * 1000));
            break;
        case 4:
            initProp("stage" + e + "_kill", 0);
            initProp("stage" + e + "_unbalanced", 0);
            break;
        case 6:
            initProp("stage" + e + "_kill", 0);
            break;
        case 7:
            initProp("stage" + e + "_count", 0);
            break;
        case 8:
            initProp("stage" + e + "_kill", 0);
            break;
        case 9:
            initProp("stage" + e + "_level", 0);
            initProp("stage" + e + "_fail", 0);
            for (var a = 0; a < 8; a++) {
                initProp("stage" + e + "_puzzle_" + a, randomNum(0, 3))
            }
            break;
        case 11:
            initProp("stage" + e + "_kill", 0);
            break;
        case 13:
            initProp("stage" + e + "_kill", 0);
            break;
        case 14:
            initProp("stage" + e + "_kill", 0);
            break;
        case 16:
            initProp("stage" + e + "_kill", 0);
            break;
        case 18:
            initProp("stage" + e + "_count", 0);
            break;
        case 21:
            initProp("stage" + e + "_kill", 0);
            break;
        case 23:
            initProp("stage" + e + "_stage", 0);
            initProp("stage" + e + "_fail", 0);
            initPropArray("stage" + e + "_help", 0, 0, 2);
            break;
        case 24:
            d.initPropArrayRandom("stage" + e + "_bgm", 0, BGM.length - 1, 4);
            initPropArray("stage" + e + "_question", 0, 1, 4);
            break;
        case 26:
            initProp("stage" + e + "_kill", 0);
            break;
        case 28:
            initPropArray("stage" + e + "_kill", 0, 0, 1);
            break;
        case 31:
            initProp("stage" + e + "_kill", 0);
            d.schedule("stage31_FairySpawn", 30 * 1000);
            initProp("stage" + e + "_fairy_summon", 0);
            initProp("stage" + e + "_angry", 0);
            break;
        case 32:
            initProp("stage" + e + "_kill", 0);
            break;
        case 33:
            initProp("stage" + e + "_reset", 0);
            initProp("stage" + e + "_teleport", 0);
            break;
        case 34:
            initProp("stage" + e + "_count", 0);
            break;
        case 36:
            initProp("stage" + e + "_stage", 0);
            initProp("stage" + e + "_curBit", 1);
            d.initPropArrayRandom("stage" + e + "_password", 1, 4, 8);
            break;
        case 37:
            initPropArray("stage" + e + "_kill", 0, 0, 3);
            break;
        case 38:
            initProp("stage" + e + "_kill", 0);
            initProp("stage" + e + "_mob", 0);
        case 39:
            initProp("stage" + e + "_stage", 0);
            initProp("stage" + e + "_total", 0);
            initProp("stage" + e + "_wrong", 0);
            d.initPropArrayRandom("stage" + e + "_answer", 1, 4, 10);
            break;
        case 42:
            initPropArray("stage" + e + "_kill", 0, 0, 3);
            break;
        case 43:
            initProp("stage" + e + "_kill", 0);
            initProp("stage" + e + "_right", 0);
            initProp("stage" + e + "_count", 0);
            break;
        case 46:
            initProp("stage" + e + "_kill", 0);
            break;
        case 47:
            initProp("stage" + e + "_trigger", randomNum(2, 8));
            break;
        case 49:
            initProp("stage" + e + "_stage", 0);
            initProp("stage" + e + "_correct", 0);
            initProp("stage" + e + "_reset", 1);
            initProp("stage" + e + "_curMob", 0);
            break
    }
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onTimeOut(a) {
    if (a.getPlayers().size() > 0) {
        a.getPlayers().forEach(function (b) {
            on玩家退场(a, b, true)
        })
    }
}

function onMonsterKilled(m, d) {
    var c = em.getNumberProperty("state");
    var f = em.getProperty("stage" + c);
    var o = c * 1000 + 准备地图;
    switch (c) {
        case 1:
            var h = 300;
            var l = em.getNumberProperty("stage" + c + "_kill") + 1;
            em.setProperty("stage" + c + "_kill", l);
            m.getPlayers().forEach(function (i) {
                var r = i.getAPI().getNumberFromQuestInfo(992001000, "damage");
                i.dropMessage(-1, "消灭古代绿水灵 " + (l) + " / " + h + "，累积冲击量 " + r + "万 / 1000万");
                if (l == h || r > 1000) {
                    em.setProperty("stage" + c, "clear");
                    i.getAPI().openNpc(2540005, "特效_完成");
                    em.getMapFactoryMap(o).getWeatherEffectNotice("你现在可以前往下一层了。", 147, 30000, 1)
                }
            });
            break;
        case 4:
            var h = 300;
            var e = 6;
            var a = Math.abs(em.getMapFactoryMap(o).calculateBalance(544));
            var l = em.getNumberProperty("stage" + c + "_kill") + e - a;
            em.setProperty("stage" + c + "_kill", l);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "均衡点数 " + (l) + " / " + h);
                if (e - a < 0) {
                    var r = parseInt(em.getProperty("stage" + c + "_unbalanced")) + 1;
                    em.getMapFactoryMap(o).getWeatherEffectNotice("均衡点数已经被削减" + r + "次了, 你这个笨蛋!赶快到对面去!", 147, 5000, 1);
                    i.getAPI().openNpc(0, "起源之塔_4F_箭头提示")
                }
            });
            if (l >= h) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("现在已经大体平衡, 你可以前往下一层了。", 147, 30000, 1)
            }
            break;
        case 6:
            var h = 300;
            var l = em.getNumberProperty("stage" + c + "_kill") + 1;
            em.setProperty("stage" + c + "_kill", l);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "消灭绿水灵 " + (l) + " / " + h)
            });
            if (l == h) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("你现在可以前往下一层了。", 147, 30000, 1)
            }
            break;
        case 8:
            var h = 100;
            var l = em.getNumberProperty("stage" + c + "_kill") + 1;
            em.setProperty("stage" + c + "_kill", l);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "消灭火山虫 " + (l) + " / " + h)
            });
            if (l == h) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("你现在可以前往下一层了。", 147, 30000, 1)
            }
            break;
        case 10:
            if (d == 9309201) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    em.broadcastServerMsg("[player]" + i.getName());
                    i.getAPI().openNpc(c, "起源之塔_BOSS结算")
                })
            }
            break;
        case 11:
            var h = 300;
            var l = em.getNumberProperty("stage" + c + "_kill") + 1;
            em.setProperty("stage" + c + "_kill", l);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "消灭石头人 " + (l) + " / " + h)
            });
            if (l == h) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("你现在可以前往下一层了。", 147, 30000, 1)
            }
            break;
        case 13:
            var h = 20;
            var l = em.getNumberProperty("stage" + c + "_kill") + 1;
            em.setProperty("stage" + c + "_kill", l);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "消灭怪物 " + l + " / " + h * 4)
            });
            if (l == h * 4) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("咳……幸好全部消灭了。你做得不错。让我们通过右侧边缘的传送出口前往下一层吧。", 147, 30000, 1)
            } else {
                if (l == h * 3 || l == h * 2 || l == h * 1) {
                    m.schedule("stage13_Fight", 10 * 1000)
                }
            }
            break;
        case 14:
            var h = 20;
            var l = em.getNumberProperty("stage" + c + "_kill") + 1;
            em.setProperty("stage" + c + "_kill", l);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "消灭蘑菇蝙蝠 " + (l) + " / " + h)
            });
            if (l >= h) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.changeMap(o + 2, 0)
                })
            }
            break;
        case 16:
            var h = 200;
            var l = em.getNumberProperty("stage" + c + "_kill") + 1;
            em.setProperty("stage" + c + "_kill", l);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "消灭怪物 " + (l) + " / " + h)
            });
            if (l == h) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("你现在可以前往下一层了。", 147, 30000, 1)
            }
            break;
        case 20:
            if (d == 9309205) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(c, "起源之塔_BOSS结算")
                })
            }
            break;
        case 21:
            if (d == 9309101) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("你现在可以前往下一层了。", 147, 30000, 1)
            } else {
                var h = 300;
                var l = em.getNumberProperty("stage" + c + "_kill") + 1;
                em.setProperty("stage" + c + "_kill", l);
                m.getPlayers().forEach(function (i) {
                    i.dropMessage(-1, "消灭怪物 " + (l) + " / " + h)
                });
                if (l == h) {
                    em.getMapFactoryMap(o).getWeatherEffectNotice("愤怒的艾利杰出现了！快消灭它！", 147, 30000, 1);
                    var b = em.getMapFactoryMap(o);
                    var n = em.getMonster(9309101);
                    m.registerMonster(n);
                    b.spawnMonsterOnGroundBelow(n, new java.awt.Point(661, 83))
                }
            }
            break;
        case 26:
            var h = 300;
            var l = em.getNumberProperty("stage" + c + "_kill") + 1;
            em.setProperty("stage" + c + "_kill", l);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "消灭古代橙水灵 " + (l) + " / " + h)
            });
            if (l == h) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("你现在可以前往下一层了。", 147, 30000, 1)
            }
            break;
        case 28:
            var h = 20;
            var k = mobs27F.indexOf(d);
            var l = new Array();
            for (var g = 0; g < mobs27F.length; g++) {
                l.push(parseInt(em.getProperty("stage" + c + "_kill_" + g)) + 1)
            }
            em.setProperty("stage" + c + "_kill_" + k, l[k]);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "消灭" + mobsName27F[k] + " " + (l[k]) + " / " + h)
            });
            if (l[0] >= h && l[1] >= h) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("你现在可以前往下一层了。", 147, 30000, 1)
            }
            break;
        case 30:
            if (d == 9309200) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(c, "起源之塔_BOSS结算")
                })
            }
            break;
        case 31:
            if (d == 5250006) {
                var p = randomNum(2, 3);
                var q = parseInt(em.getProperty("stage" + c + "_fairy_summon")) + p;
                em.setProperty("stage" + c + "_fairy_summon", q);
                em.setProperty("stage31_angry", 1);
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540000, "起源之塔_31F_妖精被杀")
                });
                for (var g = 0; g < p; g++) {
                    newmob = em.getMonster(d);
                    b.spawnMonsterOnGroundBelow(newmob, n.getPosition())
                }
                break
            }
            var h = 200;
            var l = em.getNumberProperty("stage" + c + "_kill") + 1;
            em.setProperty("stage" + c + "_kill", l);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "消灭食虫水灵 " + (l) + " / " + h)
            });
            if (l == h) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("你现在可以前往下一层了。", 147, 30000, 1)
            }
            break;
        case 32:
            var h = 45;
            var l = em.getNumberProperty("stage" + c + "_kill") + 1;
            em.setProperty("stage" + c + "_kill", l);
            if (l == h) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("你现在可以前往下一层了。", 147, 30000, 1)
            }
            break;
        case 37:
            var h = 100;
            var k = mobs37F.indexOf(d);
            var l = new Array();
            for (var g = 0; g < mobs37F.length; g++) {
                l.push(parseInt(em.getProperty("stage" + c + "_kill_" + g)) + 1)
            }
            em.setProperty("stage" + c + "_kill_" + k, l[k]);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "消灭" + mobsName37F[k] + " " + (l[k]) + " / " + h)
            });
            if (l[0] >= h && l[1] >= h && l[2] >= h && l[3] >= h) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("你已经将所有的怪物各消灭了100个。让我们前往下一层吧。", 147, 30000, 1)
            } else {
                if (l[k] >= h) {
                    m.getPlayers().forEach(function (i) {
                        i.dropMessage(5, "你消灭了100多个" + mobsName37F[k] + "。现在请消灭其他怪物。")
                    })
                }
            }
            break;
        case 38:
            var n = parseInt(em.getProperty("stage" + c + "_mob"));
            if (d == n) {
                var h = 1000;
                var l = em.getNumberProperty("stage" + c + "_kill") + 10;
                em.setProperty("stage" + c + "_kill", l);
                m.getPlayers().forEach(function (i) {
                    if (l >= h) {
                        em.setProperty("stage" + c, "clear");
                        i.getAPI().openNpc(2540005, "特效_完成");
                        em.getMapFactoryMap(o).getWeatherEffectNotice("黑暗气息已经全部清除了。通往下一层的门已经打开，让我们继续前进吧。", 147, 30000, 1)
                    } else {
                        em.getMapFactoryMap(o).getWeatherEffectNotice("黑暗气息：" + (h - l), 153, 30000, 1)
                    }
                })
            } else {
                em.getMapFactoryMap(o).getWeatherEffectNotice("你消灭的怪物不正确。黑暗气息并没有减少。", 153, 30000, 1)
            }
            break;
        case 40:
            if (d == 9309203) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(c, "起源之塔_BOSS结算")
                })
            }
            break;
        case 42:
            var h = 30;
            var k = mobs42F.indexOf(d);
            var l = new Array();
            for (var g = 0; g < mobs42F.length; g++) {
                l.push(parseInt(em.getProperty("stage" + c + "_kill_" + g)) + 1)
            }
            em.setProperty("stage" + c + "_kill_" + k, l[k]);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "消灭" + mobsName42F[k] + " " + (l[k]) + " / " + h)
            });
            if (l[0] >= h && l[1] >= h && l[2] >= h && l[3] >= h) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("你已经将所有的怪物各消灭了30个。请前往下一层。", 147, 30000, 1);
                m.getPlayers().forEach(function (i) {
                    i.dropMessage(5, "你消灭了30多个" + mobsName42F[k] + "。现在请消灭其他怪物。")
                })
            }
            break;
        case 43:
            var j = parseInt(em.getProperty("stage" + c + "_count"));
            var h = 10 * j;
            var l = em.getNumberProperty("stage" + c + "_kill") + 1;
            em.setProperty("stage" + c + "_kill", l);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "消灭怪物 " + (l) + " / " + h)
            });
            if (l >= h) {
                em.setProperty("stage" + c, "ask");
                em.getMapFactoryMap(o).getWeatherEffectNotice("好了，消灭了足够的怪物，现在可以继续测试了。", 148, 30000, 1)
            }
            break;
        case 46:
            var h = 200;
            var l = em.getNumberProperty("stage" + c + "_kill") + 1;
            em.setProperty("stage" + c + "_kill", l);
            m.getPlayers().forEach(function (i) {
                i.dropMessage(-1, "消灭飞龙 " + (l) + " / " + h)
            });
            if (l == h) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("你现在可以前往下一层了。", 147, 30000, 1)
            }
            break;
        case 47:
            if (d == 9309128) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(2540005, "特效_完成")
                });
                em.getMapFactoryMap(o).getWeatherEffectNotice("咳。现在我的声音才能传到你那儿。我已经把门打开了，请前往下一层吧。", 147, 30000, 1)
            }
            break;
        case 50:
            if (d == 9309207) {
                em.setProperty("stage" + c, "clear");
                m.getPlayers().forEach(function (i) {
                    i.getAPI().openNpc(c, "起源之塔_BOSS结算")
                })
            }
            break
    }
    return 1
}

function onMonsterDamaged(b, a, d, e, c) {
    if (a.getMapId() == 992001000) {
        a.getAPI().addNumberForQuestInfo(992001000, "damage", Math.round(c / 10000))
    }
}

function onItemPickedUp(d, c, e) {
    var h = em.getNumberProperty("state");
    var b = h * 1000 + 准备地图;
    var f = em.getMapFactoryMap(b);
    if (h == 2 && e == 2432448) {
        c.getAPI().openNpc(0, "起源之塔_2F_捡取卡片")
    } else {
        if (h == 3) {
            var a = 1000;
            var g = c.getItemAmount(4009237) + c.getItemAmount(4009238);
            c.dropMessage(-1, "古代乌龟蛋 " + g + " / " + a);
            if (g >= a) {
                em.getMapFactoryMap(b).getWeatherEffectNotice("哇！你真的收集到1000个啦？现在我们可以前往下一层了。", 147, 30000, 1);
                em.setProperty("stage" + h, "clear");
                c.getAPI().openNpc(2540005, "特效_完成")
            }
        } else {
            if (h == 18 && e == 4000136) {
                var a = 10;
                var g = c.getItemAmount(4000136);
                c.dropMessage(-1, "采集了 " + g + " 个椰子果。");
                if (g == a) {
                    em.getMapFactoryMap(b).getWeatherEffectNotice("终于收集够椰子果了。现在我们可以前往下一层了。", 147, 30000, 1);
                    em.setProperty("stage" + h, "clear");
                    c.getAPI().openNpc(2540005, "特效_完成")
                }
            } else {
                if (h == 29 && e == 4009232) {
                    var g = c.getItemAmount(4009232);
                    if (g >= 10) {
                        c.removeItem(4009232, 10);
                        em.getMapFactoryMap(b).getWeatherEffectNotice("左边的树上结出了一个红色沙晶了。", 147, 30000, 1);
                        f.spawnAutoDrop(4034077, new java.awt.Point(-542, -501))
                    }
                } else {
                    if (h == 34 && e == 4009235) {
                        var a = 10;
                        var g = c.getItemAmount(4009235);
                        c.dropMessage(-1, "紫色皮革 " + g + " / " + a);
                        if (g == a) {
                            em.getMapFactoryMap(b).getWeatherEffectNotice("你已经将10个紫色皮革全部搜集到了！让我们前往下一层吧！", 147, 30000, 1);
                            em.setProperty("stage" + h, "clear");
                            c.getAPI().openNpc(2540005, "特效_完成")
                        }
                    }
                }
            }
        }
    }
}

function onPlayerRevived(b, a) {
    return false
}

function onPartyDisbanded(a) {}

function onPlayerKilled(c, b) {
    var d = em.getNumberProperty("state");
    var e = em.getProperty("stage" + d);
    var a = d * 1000 + 准备地图;
    switch (d) {
        case 50:
            c.getPlayers().forEach(function (f) {
                if (!f.haveItem(1142684, 1)) {
                    f.dropMessage(5, "在被桃乐丝击败时，背包里似乎多了什么。");
                    f.gainItem(1142684, 1)
                }
            });
            break
    }
}
var setupTask;

function stage3_Fight(b) {
    var a = em.getNumberProperty("state") * 1000 + 准备地图;
    if (a != 3 * 1000 + 准备地图) {
        return
    }
    var c = randomNum(1, 2) == 1 ? 2540012 : 2540014;
    em.setProperty("stage3_winner", c);
    em.getPlayersInMap(a).forEach(function (d) {
        d.getAPI().openNpc(c, "起源之塔_3F_对决胜利")
    });
    b.schedule("stage3_Fight", randomNum(1 * 60, 3 * 60) * 1000)
}

function stage7_Fight(d) {
    var c = em.getNumberProperty("state") * 1000 + 准备地图;
    if (c != 7 * 1000 + 准备地图) {
        return
    }
    var g = em.getMapFactoryMap(c);
    var f;
    var e = parseInt(em.getProperty("stage7_count")) + 1;
    em.setProperty("stage7_count", e);
    if (e < 7) {
        var a = 2540000 + randomNum(1, 2);
        em.getPlayersInMap(c).forEach(function (h) {
            h.getAPI().openNpc(a, "起源之塔_7F_赶猴子")
        });
        d.schedule("stage7_Fight", randomNum(10, 20) * 1000);
        for (var b = 0; b < e * 4 + 10; b++) {
            f = em.getMonster(e % 2 == 0 ? 9309002 : 9309125);
            g.spawnMonsterOnGroundBelow(f, new java.awt.Point(e % 2 == 0 ? (-1500 + b * 30) : (-200 - b * 30), 2300))
        }
    } else {
        if (e == 7) {
            em.getPlayersInMap(c).forEach(function (h) {
                h.getAPI().openNpc(2540003, "起源之塔_7F_赶猴子")
            });
            d.schedule("stage7_Fight", randomNum(10, 20) * 1000);
            for (var b = 0; b < e * 2 + 10; b++) {
                f = em.getMonster(b % 2 == 0 ? 9309002 : 9309125);
                g.spawnMonsterOnGroundBelow(f, new java.awt.Point(-1500 + b * 30, 2300));
                g.spawnMonsterOnGroundBelow(f, new java.awt.Point(-200 - b * 30, 2300))
            }
        } else {
            em.getPlayersInMap(c).forEach(function (h) {
                h.getAPI().openNpc(2540004, "起源之塔_7F_赶猴子")
            })
        }
    }
}

function stage13_Fight(h) {
    var l = em.getNumberProperty("state") * 1000 + 准备地图;
    if (l != 13 * 1000 + 准备地图) {
        return
    }
    var b = [9309099, 9309104, 9309105, 9309098];
    var e = 20;
    var g = parseInt(em.getProperty("stage13_kill"));
    var f = Math.floor(g / e);
    var a = em.getMapFactoryMap(l);
    var j;
    if (f < 3) {
        for (var d = 0; d < e; d++) {
            j = em.getMonster(b[f]);
            a.spawnMonsterOnGroundBelow(j, new java.awt.Point(-750 + d * 50, 0))
        }
    } else {
        for (var c = 0; c < b.length; c++) {
            for (var d = 0; d < e / b.length; d++) {
                j = em.getMonster(b[c]);
                a.spawnMonsterOnGroundBelow(j, new java.awt.Point(-1000 + (c * b.length + d) * 50, 0))
            }
        }
    }
    em.getPlayersInMap(l).forEach(function (i) {
        i.getAPI().openNpc(f, "起源之塔_13F_防御战")
    })
}

function stage31_FairySpawn(b) {
    var a = em.getNumberProperty("state") * 1000 + 准备地图;
    if (a != 31 * 1000 + 准备地图) {
        return
    }
    var b = em.getInstance("副本_起源之塔");
    var d = 5250006;
    var e = em.getMapFactoryMap(a);
    var c = em.getMonster(d);
    e.spawnMonsterOnGroundBelow(c, new java.awt.Point(randomNum(-1500, -500), randomNum(-1500, -500)));
    b.schedule("stage31_FairyLeave", 30 * 1000)
}

function stage31_FairyLeave(c) {
    var b = em.getNumberProperty("state") * 1000 + 准备地图;
    var a = parseInt(em.getProperty("stage31_angry"));
    if (a || (b != 31 * 1000 + 准备地图)) {
        return
    }
    var d = 5250006;
    var c = em.getInstance("副本_起源之塔");
    c.getMobs().forEach(function (e) {
        if (e.getMap().getId() == b && e.getId() == d) {
            e.killed()
        }
    });
    c.schedule("stage31_FairySpawn", 60 * 1000)
}

function stage38_Relocate(b) {
    var a = em.getNumberProperty("state") * 1000 + 准备地图;
    if (a != 38 * 1000 + 准备地图) {
        return
    }
    if (!"fight".equals(em.getProperty("stage38"))) {
        return
    }
    em.getPlayersInMap(a).forEach(function (c) {
        c.getAPI().openNpc(2540006, "起源之塔_38F_变换黑暗气息")
    });
    b.schedule("stage38_Relocate", 10 * 1000)
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    var d = c.getTimeLeft();
    var e = em.getProperty("state");
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b);
    b.removeAll(4009237);
    b.removeAll(4009238);
    b.updateOzRecord(d)
};